<h1><%=h 'Edit My Profile'.t %></h1>

<%= error_messages_for :user %>

<% form_for(@user) do |f| %>  
  <dl>
	  <dt><%= f.label :email, "Change Email".t %></dt>
		<dd><%= f.text_field :email %></dd>
  </dl>
	
	<!-- The password or OpenID login fields are shown in this div -->
			<div id="switch_fields">
<!-- use_openid set by link_to_passwd and link_to_openid below; needed for non-JS users to distinguish between versions of the page -->
					<%- if params[:use_openid] -%>
					<%= render :partial => 'profile_openid', :locals => {:f => f} %>
					<%- else -%>
					<%= render :partial => 'profile_passwd', :locals => {:f => f} %>
					<%- end -%>
			</div>
<!-- Link to toggle between password and OpenID. Ugly code! :( Also, must be a way to reuse partials from new user page? -->
<!-- Two versions of the div tag here so the link to passwd is not shown when the page is first loaded; for non-JS users clicking the link sets use_openid to true, showing the div on reload; for JS users the display is toggled -->
				<%- if params[:use_openid] -%>
					<div id="link_to_passwd">
			  <%- else -%>
					<div id="link_to_passwd" style="display: none;">
				<%- end -%>
					<%= link_to_function("Add or Change a Password".t, :href => url_for(:action => 'edit', :use_openid => false), :class => 'footnote') do |page|
						page.replace_html "switch_fields", :partial => 'profile_passwd', :locals => {:f => f}
						page[:link_to_passwd].hide
						page[:link_to_openid].show
						end %>
					</div>
				<div id="link_to_openid">
<!-- !params[:use_openid] ensures this is hidden on the openid version of the page for non-JS users -->
					<%- if !params[:use_openid] -%>
					<%- if ArchiveConfig.USE_OPENID -%>
						<%= image_tag("openid.png", :alt => ' ') %>
						<%= link_to_function("Add or Change an OpenID URL".t, :href => url_for(:action => 'edit', :use_openid => true), :class => 'footnote') do |page|
							page.replace_html "switch_fields", :partial => 'profile_openid', :locals => {:f => f}
							page[:link_to_openid].hide
							page[:link_to_passwd].show
							end %>
						<%- end -%>
					<%- end -%>
				</div>
  
  <% fields_for :profile_attributes,  @user.profile do |p| %>
  <dl>
	  <dt><%= p.label :title, "Title".t %></dt>
    <dd><%= p.text_field :title %></dd>
    <dt><%= p.label :location, "Location".t %></dt>
    <dd><%= p.text_field :location %></dd>
    <dt><%= p.label :date_of_birth, "Date of Birth".t %></dt>
    <dd><%= p.date_select :date_of_birth, :start_year => 13.years.ago.year, :end_year => 90.years.ago.year, :include_blank => true, :order => [:day, :month, :year] %></dd>
    <dt><%= p.label :about_me, "About Me".t %></dt>
    <dd><%= p.text_area :about_me %></dd>
	</dl>
  <% end %>
	
	
  <p class="submit">
    <%= f.submit "Update".t %>
  </p>
<% end %>
<hr class="clear" />
